package 序列化和反序列化克隆;

import java.io.Serializable;

public class Person implements Serializable {
    /**
     * serialVersionUID适用于java序列化机制。简单来说，JAVA序列化的机制是通过 判断类的serialVersionUID来验证的版本一致的。在进行反序列化时，JVM会把传来的字节流中的serialVersionUID于本地相应实体类的serialVersionUID进行比较。如果相同说明是一致的，可以进行反序列化，否则会出现反序列化版本一致的异常，即是InvalidCastException。
     * 具体序列化的过程是这样的：序列化操作时会把系统当前类的serialVersionUID写入到序列化文件中，当反序列化时系统会自动检测文件中的serialVersionUID，判断它是否与当前类中的serialVersionUID一致。如果一致说明序列化文件的版本与当前类的版本是一样的，可以反序列化成功，否则就失败；
     */
    private static final long serialVersionUID = 4792126594710124401L;
    private String name;
    private int age;
    private Car car;
    private car1 car1;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Person(String name, int age, Car car) {
        this.name = name;
        this.age = age;
        this.car = car;
    }

    public Person(String name, int age, car1 car1) {
        this.name = name;
        this.age = age;
        this.car1 = car1;
    }

    public Person(String name, int age, Car car, car1 car1) {
        this.name = name;
        this.age = age;
        this.car = car;
        this.car1 = car1;
    }

    // getter和setter方法省略


    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Car getCar() {
        return car;
    }

    public void setCar(Car car) {
        this.car = car;
    }

    public 序列化和反序列化克隆.car1 getCar1() {
        return car1;
    }

    public void setCar1(序列化和反序列化克隆.car1 car1) {
        this.car1 = car1;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", car=" + car +
                ", car1=" + car1 +
                '}';
    }
}
